<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <%layout("/WEB-INF/view/common/inc/admin_head.html",{title:'', styles:'bootstrap,font-awesome,animate,style,bootstrap-table,layui-date,auto-complete,dtvalidate,layui'}){%>
    <style type="text/css">
        body{padding-top:10px;}
        *{margin:0;padding:0;list-style-type:none;}
        a,img{border:0;}
        .demo h2{font-size:16px;color:#3366cc;height:30px;}
        .demo li{float:left;}
    </style>
    <%}%>
</head>
<body>

<div class="row">
    <div class="col-sm-12">
        <!-- START 右侧数据 -->
        <div class="ibox float-e-margins" style="margin-bottom: 0px;">
            <div class="ibox-content" style="padding:15px 20px 0px 20px;">
                <form id="search-form" role="form" class="form-h
                orizontal" autocomplete="off">
                    <div class="form-group">
                        <label class="control-label col-sm-1">供应商名称:</label>
                        <div class="col-sm-2">
                            <input type="text" id="supplierName" name="supplierName" class="form-control">
                        </div>
                        <label class="control-label col-sm-1">SKU:</label>
                        <div class="col-sm-2">
                            <input type="text" id="supplierSku" name="supplierSku" class="form-control">
                        </div>
                        <a class="search-btn btn btn-success" style="margin-bottom: 0px;">查询</a>
                    </div>
                </form>
            </div>
        </div>
        <!-- END 右侧数据 -->
    </div>
</div>


<div id="toolbar" class="btn-group" style="margin-bottom:5px;">
    <button  class="layui-btn layui-btn-normal layui-btn-sm" style="margin-top: -6px;margin-left: -4px" id="import-btn"  name="import-btn">
        <i class="fa fa-plus" aria-hidden="true"></i> 导入供应商分配信息
    </button>
    <button  class="layui-btn  layui-btn-sm" >
        <i class="fa fa-download"></i>
        <a href="/excel/供应商分配.xlsx" style="color: white" download>模板下载</a>
    </button>
</div>
<!-- START 数据表格 -->
<table id="supplierTable"
       data-toolbar="#toolbar"
       data-pagination="true"
       data-resizable="true"
       data-side-pagination="server"
       data-url="/sea/supply/supplierSku/findByCnd.do"
       data-page-size="15"
       class="table table-striped table-hover"
>
</table>

<%layout("/WEB-INF/view/common/inc/admin_js.html",{modules:'jquery,bootstrap,bootstrap-table,dtvalidate,dtvalidate-lang-zh_cn,bootstrap-table-zh-CN,laydate,layer,layui'}){}%>
<script>
    var $supplierTable = $('#supplierTable');

    $(function () {
        layui.use('upload', function(){
            var upload = layui.upload;
            upload.render({
                elem: '#import-btn', //绑定元素,
                accept:'file',
                url: '/sea/supply/supplierSku/import/', //上传接口
                data:{},
                before:function () {
                    layer.load(1, {
                        shade: [0.1,'#fff'] //0.1透明度的白色背景
                    });
                }
                ,done: function(data){
                    if( data.ok ){
                        layer.msg(data.msg,{icon: 1,time: 1500},function(){
                            //刷新页面
                            $supplierTable.bootstrapTable('refresh');
                            layer.closeAll();
                        });
                    }else{
                        layer.msg(data.msg,{icon: 0,btn: ['确定'],time:0,shade: [0.8, '#393D49'],yes: function(index, layero){ // 默认的是 按钮一
                                layer.closeAll();
                            }});
                    }
                }
                ,error: function(){
                    //请求异常回调
                    layer.closeAll();
                }
            });
        });



        // START 表格配置
        $supplierTable.bootstrapTable({
            pageSize:10,
            columns: [
                {
                    title: '渠道',
                    field: 'supplierChannelName',
                    align: 'center',
                    valign: 'middle'
                },
                {
                    title: 'SKU',
                    field: 'supplierSku',
                    align: 'center',
                    valign: 'middle'
                },
                {
                    title: '供应商',
                    field: 'supplierName',
                    align: 'center',
                    valign: 'middle'
                },
                {
                    title: '付款方式',
                    field: 'paymentType',
                    align: 'center',
                    valign: 'middle'
                },
                {
                    title: '创建时间',
                    field: 'createTime',
                    align: 'center',
                    valign: 'middle'
                },
                {
                    title: '操作',
                    field: 'operate',
                    align: 'center',
                    valign: 'middle',
                    formatter: optFormatter
                }
            ],
            onLoadSuccess : function(){

                $('.del-btn').on('click',function(){
                    var delid = $(this).attr('data-val'),delname = $(this).attr('data-val-name');
                    layer.confirm('确定要删除当前？', {
                        btn: ['确定','取消'],title:'提示'
                    }, function(){
                        var index = layer.load();
                        $.post('/sea/supply/supplierSku/delete.do',{id: delid},function(data){
                            if( data.ok ){
                                layer.close(index);
                                layer.msg(data.msg,{icon: 1,time: 1500},function(){
                                    //刷新页面
                                    $supplierTable.bootstrapTable('refresh');
                                });
                            }else{
                                layer.msg(data.msg,{icon: 0,time: 1500});
                                layer.close(index);
                            }
                        });
                    });
                });
            }
        });

        function optFormatter(value,row){
            var content = '';
            content += '&nbsp;<a class="del-btn btn btn-xs btn-danger" data-val-name="'+row.supplierName+'" data-val="'+row.id+'" title="删除"><i class="fa fa-trash-o"></i> 删除 </a>';
            return content;
        }

        // 条件查询
        $('.search-btn').on('click',function () {
            $supplierTable.bootstrapTable('refresh', { url:'${ctxPath}/sea/supply/supplierSku/findByCnd.do?'+$('#search-form').serialize() });
        });

        $(".export-btn").click(function () {
            window.location.href='/sea/supply/supplier/export.do?'+$('#search-form').serialize();
        });
    });

</script>
</body>
</html>